home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2004 #9 / Amiga Plus CD - 2004 - No. 09.iso / amigaplus / tools / dev_libs / feelin040718 / sources / gauge / object.c next >
Encoding:
C/C++ Source or Header  |  2004-08-03  |  9.3 KB  |  335 lines

  1. #include "Private.h"
  2.  
  3. /*** Methods ***************************************************************/
  4.  
  5. ///Gauge_New
  6. F_METHODM(ULONG,Gauge_New,TagItem)
  7. {
  8.    struct LocalObjectData *LOD  = F_LOD(Class,Obj);
  9.    struct TagItem         *Tags = Msg,
  10.                            item;
  11.  
  12.    LOD -> AreaData = (FAreaData *) F_Get(Obj,FA_AreaData);
  13.  
  14.    while  (F_DynamicNTI(&Tags,&item,Class))
  15.    switch (item.ti_Tag)
  16.    {
  17.       case FA_Gauge_Info:  LOD -> Info = (STRPTR)(item.ti_Data); break;
  18.    }
  19.  
  20.    return F_SuperDo(Class,Obj,Method,
  21.  
  22.       FA_Frame,         "FP_Gauge_Frame",
  23.       FA_NoFill,        TRUE,
  24.       FA_ChainToCycle,  FALSE,
  25.  
  26.       TAG_MORE, Msg);
  27. }
  28. //+
  29. ///Gauge_Set
  30. F_METHOD(void,Gauge_Set)
  31. {
  32.    struct LocalObjectData *LOD  = F_LOD(Class,Obj);
  33.    struct TagItem         *Tags = Msg,
  34.                            item;
  35.  
  36.    while  (F_DynamicNTI(&Tags,&item,Class))
  37.    switch (item.ti_Tag)
  38.    {
  39.       case FA_Gauge_Simple:
  40.       {
  41.          if (item.ti_Data) LOD -> Flags |=  FF_Gauge_Simple;
  42.          else              LOD -> Flags &= ~FF_Gauge_Simple;
  43.  
  44.          F_Draw(Obj,FF_Draw_Update);
  45.       }
  46.       break;
  47.    }
  48.    F_SUPERDO();
  49. }
  50. //+
  51. ///Gauge_Get
  52. F_METHOD(void,Gauge_Get)
  53. {
  54.    struct LocalObjectData  *LOD  = F_LOD(Class,Obj);
  55.    struct TagItem          *Tags = Msg,
  56.                             item;
  57.  
  58.    BOOL up = FALSE;
  59.  
  60.    while (F_DynamicNTI(&Tags,&item,Class))
  61.    switch (item.ti_Tag)
  62.    {
  63.       case FA_Gauge_Simple:   F_STORE(0 != (LOD -> Flags & FF_Gauge_Simple)); break;
  64.  
  65.       default: up = TRUE;
  66.    }
  67.  
  68.    if (up) F_SUPERDO();
  69. }
  70. //+
  71. ///Gauge_AskMinMax
  72. F_METHOD(ULONG,Gauge_AskMinMax)
  73. {
  74.    struct LocalObjectData *LOD = F_LOD(Class,Obj);
  75.  
  76.    _minh += 10;
  77.    _minw += 10;
  78.  
  79.    return F_SUPERDO();
  80. }
  81. //+
  82. ///Gauge_Draw
  83. F_METHODM(void,Gauge_Draw,FS_Draw)
  84. {
  85.    struct LocalObjectData *LOD   = F_LOD(Class,Obj);
  86.    struct RastPort        *rp    = _rp;
  87.    ULONG                  *pn    = _pens;
  88.    WORD                    x1    = _mx, x2 = x1 + _mw - 1,
  89.                            y1    = _my, y2 = y1 + _mh - 1,
  90.                            s,mp;
  91.    LONG                    val,max,min;
  92.  
  93.    static UWORD _Gauge_Pattern1[] =
  94.    {
  95.       0xFF00, 0x7F80, 0x3FC0, 0x1FE0,
  96.       0x0FF0, 0x07F8, 0x03FC, 0x01FE,
  97.       0x00FF, 0x807F, 0xC03F, 0xE01F,
  98.       0xF00F, 0xF807, 0xFC03, 0xFE01
  99.    };
  100.  
  101.    if (FF_Draw_Object & Msg -> Flags)
  102.    {
  103.       F_SUPERDO();
  104.    }
  105.  
  106.    F_Do(Obj,FM_Get,
  107.             F_IDR(FA_Numeric_Value),   &val,
  108.             F_IDR(FA_Numeric_Min),     &min,
  109.             F_IDR(FA_Numeric_Max),     &max, TAG_DONE);
  110.  
  111.    if (((max - min) == 0) || (min > max))
  112.    {
  113.       goto _Gauge_Draw_Fill;
  114.    }
  115.  
  116.    s  = (FF_Horizontal & _flags) ? (x2 - x1 + 1) : (y2 - y1 + 1);
  117.    mp = val * s / (max - min);
  118.  
  119.    if (FF_Gauge_Simple & LOD -> Flags)
  120.    {
  121.       if (mp)
  122.       {
  123.          _APen(pn[FV_Pen_HalfShine]);
  124.          _BPen(pn[FV_Pen_HalfShadow]);
  125.  
  126.          if (FF_Horizontal & _flags)
  127.          {
  128.             mp += x1 - 1;
  129.  
  130.             if (x1 < x2)
  131.             {
  132.                rp -> AreaPtrn = _Gauge_Pattern1;
  133.                rp -> AreaPtSz = 4;
  134.  
  135.                _Boxf(x1,y1,mp,y2);
  136.  
  137.                rp -> AreaPtSz = 0;
  138.                rp -> AreaPtrn = NULL;
  139.             }
  140.             x1 = mp + 1;
  141.          }
  142.          else
  143.          {
  144.             mp = y2 - mp + 1;
  145.  
  146.             if (y1 < y2)
  147.             {
  148.                rp -> AreaPtrn = _Gauge_Pattern1;
  149.                rp -> AreaPtSz = 4;
  150.  
  151.                _Boxf(x1,mp,x2,y2);
  152.  
  153.                rp -> AreaPtSz = 0;
  154.                rp -> AreaPtrn = NULL;
  155.             }
  156.             y2 = mp - 1;
  157.          }
  158.       }
  159.    }
  160.    else
  161.    {
  162.       if (FF_Horizontal & _flags)
  163.       {
  164.          if (mp)
  165.          {
  166.             mp = x1 + mp - 1;
  167.             s  = mp - x1 + 1;
  168.  
  169.             if (s > 0)
  170.             {
  171.                _APen(pn[FV_Pen_Dark]);  _Move(mp,y1);  _Draw(mp,y2);
  172.             }
  173.  
  174.             if (s > 1)
  175.             {
  176.                _APen(pn[FV_Pen_Dark]) ; _Move(x1,y1) ; _Draw(x1,y2);
  177.             }
  178.  
  179.             if (s > 2);
  180.             {
  181.                x1 += 1;
  182.  
  183.                _APen(pn[FV_Pen_Fill]);        _Plot(x1,y1);     _Plot(x1,y2-2);
  184.                _APen(pn[FV_Pen_HalfShine]);   _Plot(x1,y1+1);   _Plot(x1,y2-3);
  185.                _APen(pn[FV_Pen_Shine]);       _Move(x1,y1+2);   _Draw(x1,y2-4);
  186.                _APen(pn[FV_Pen_HalfShadow]);  _Plot(x1,y2-1);
  187.                _APen(pn[FV_Pen_Shadow]);      _Plot(x1,y2);
  188.                x1 -= 1;
  189.             }
  190.  
  191.             if (s > 3)
  192.             {
  193.                mp -= 1;
  194.                _Move(mp,y1+1); _Draw(mp,y2-1);
  195.                _APen(pn[FV_Pen_HalfShadow]);  _Plot(mp,y1);
  196.                _APen(pn[FV_Pen_HalfDark]);    _Plot(mp,y2);
  197.                mp += 1;
  198.             }
  199.  
  200.             if (s > 4)
  201.             {
  202.                mp -= 2;
  203.                _Plot(mp,y2);
  204.                _APen(pn[FV_Pen_Shadow]);      _Plot(mp,y2-1);
  205.                _APen(pn[FV_Pen_HalfShadow]);  _Plot(mp,y2-2);   _Plot(mp,y1);
  206.                _APen(pn[FV_Pen_Fill]);        _Plot(mp,y2-3);   _Plot(mp,y1+1);
  207.                _APen(pn[FV_Pen_HalfShine]);   _Move(mp,y1+2);   _Draw(mp,y2-4);
  208.                mp += 2;
  209.             }
  210.  
  211.             if (s > 5)
  212.             {
  213.                x1 += 2;
  214.                _Plot(x1,y2-4); _Plot(x1,y1+2);
  215.                _APen(pn[FV_Pen_HalfDark]);    _Plot(x1,y2);
  216.                _APen(pn[FV_Pen_Shadow]);      _Plot(x1,y2-1);
  217.                _APen(pn[FV_Pen_HalfShadow]);  _Plot(x1,y2-2);   _Plot(x1,y1);
  218.                _APen(pn[FV_Pen_Fill]);        _Plot(x1,y2-3);   _Plot(x1,y1+1);
  219.                _APen(pn[FV_Pen_Shine]);       _Move(x1,y2-5);   _Draw(x1,y1+3);
  220.                x1 -= 2;
  221.             }
  222.  
  223.             if (s > 6)
  224.             {
  225.                x1 += 3;
  226.                mp -= 3;
  227.                _Boxf(x1,y1+3,mp,y2-5);
  228.                _APen(pn[FV_Pen_HalfDark]);    _Move(x1,y2);     _Draw(mp,y2);
  229.                _APen(pn[FV_Pen_Shadow]);      _Move(x1,y2-1);   _Draw(mp,y2-1);
  230.                _APen(pn[FV_Pen_HalfShadow]);  _Move(x1,y2-2);   _Draw(mp,y2-2); _Move(x1,y1);   _Draw(mp,y1);
  231.                _APen(pn[FV_Pen_Fill]);        _Move(x1,y2-3);   _Draw(mp,y2-3); _Move(x1,y1+1); _Draw(mp,y1+1);
  232.                _APen(pn[FV_Pen_HalfShine]);   _Move(x1,y2-4);   _Draw(mp,y2-4); _Move(x1,y1+2); _Draw(mp,y1+2);
  233.                mp += 3;
  234.             }
  235.             x1 = mp + 1;
  236.          }
  237.       }
  238.       else
  239.       {
  240.          if (mp)
  241.          {
  242.             mp = y2 - mp + 1;
  243.             s  = y2 - mp + 1;
  244.  
  245.             if (s > 0)
  246.             {
  247.                _APen(pn[FV_Pen_Dark]); _Move(x1,y2); _Draw(x2,y2);
  248.             }
  249.  
  250.             if (s > 1)
  251.             {
  252.                _APen(pn[FV_Pen_Dark]); _Move(x1,mp); _Draw(x2,mp);
  253.             }
  254.  
  255.             if (s > 2)
  256.             {
  257.                mp += 1;
  258.                _APen(pn[FV_Pen_Fill]);       _Plot(x1,mp);   _Plot(x2-2,mp);
  259.                _APen(pn[FV_Pen_HalfShine]);  _Plot(x1+1,mp); _Plot(x2-3,mp);
  260.                _APen(pn[FV_Pen_Shine]);      _Move(x1+2,mp); _Draw(x2-4,mp);
  261.                _APen(pn[FV_Pen_HalfShadow]); _Plot(x2-1,mp);
  262.                _APen(pn[FV_Pen_Shadow]);     _Plot(x2,mp);
  263.                mp -= 1;
  264.             }
  265.  
  266.             if (s > 3)
  267.             {
  268.                y2 -= 1;
  269.                _Move(x1+1,y2); _Draw(x2-1,y2);
  270.                _APen(pn[FV_Pen_HalfDark]);   _Plot(x2,y2);
  271.                _APen(pn[FV_Pen_HalfShadow]); _Plot(x1,y2);
  272.                y2 += 1;
  273.             }
  274.  
  275.             if (s > 4)
  276.             {
  277.                y2 -= 2;
  278.                _Plot(x1,y2); _Plot(x2-2,y2);
  279.                _APen(pn[FV_Pen_HalfDark]);  _Plot(x2,y2);
  280.                _APen(pn[FV_Pen_Shadow]);    _Plot(x2-1,y2);
  281.                _APen(pn[FV_Pen_Fill]);      _Plot(x1+1,y2); _Plot(x2-3,y2);
  282.                _APen(pn[FV_Pen_HalfShine]); _Move(x1+2,y2); _Draw(x2-4,y2);
  283.                y2 += 2;
  284.             }
  285.  
  286.             if (s > 5)
  287.             {
  288.                mp += 2;
  289.                _Plot(x1+2,mp); _Plot(x2-4,mp);
  290.                _APen(pn[FV_Pen_HalfDark]);   _Plot(x2,mp);
  291.                _APen(pn[FV_Pen_Shadow]);     _Plot(x2-1,mp);
  292.                _APen(pn[FV_Pen_HalfShadow]); _Plot(x1,mp);   _Plot(x2-2,mp);
  293.                _APen(pn[FV_Pen_Fill]);       _Plot(x1+1,mp); _Plot(x2-3,mp);
  294.                _APen(pn[FV_Pen_Shine]);      _Move(x1+3,mp); _Draw(x2-5,mp);
  295.                mp -= 2;
  296.             }
  297.  
  298.             if (s > 6)
  299.             {
  300.                y2 -= 3;
  301.                mp += 3;
  302.                _Boxf(x1+3,mp,x2-5,y2);
  303.                _APen(pn[FV_Pen_HalfDark]);   _Move(x2,mp);   _Draw(x2,y2);
  304.                _APen(pn[FV_Pen_Shadow]);     _Move(x2-1,mp); _Draw(x2-1,y2);
  305.                _APen(pn[FV_Pen_HalfShadow]); _Move(x2-2,mp); _Draw(x2-2,y2); _Move(x1,mp)   ; _Draw(x1,y2);
  306.                _APen(pn[FV_Pen_Fill]);       _Move(x2-3,mp); _Draw(x2-3,y2); _Move(x1+1,mp) ; _Draw(x1+1,y2);
  307.                _APen(pn[FV_Pen_HalfShine]);  _Move(x2-4,mp); _Draw(x2-4,y2); _Move(x1+2,mp) ; _Draw(x1+2,y2);
  308.                mp -= 3;
  309.             }
  310.             y2 = mp - 1;
  311.          }
  312.       }
  313.    }
  314.  
  315. _Gauge_Draw_Fill:
  316.  
  317.    if (FF_Horizontal & _flags)
  318.    {
  319.       if (x1 < x2)
  320.       {
  321.          _APen(pn[FV_Pen_Shadow]);      _Move(x1,y1);     _Draw(x2,y1);
  322.          _APen(pn[FV_Pen_HalfShadow]);  _Move(x1,y1+1);   _Draw(x2,y1+1);
  323.          _APen(pn[FV_Pen_Fill]);        _Boxf(x1,y1+2,x2,y2);
  324.       }
  325.    }
  326.    else if (y1 < y2)
  327.    {
  328.       _APen(pn[FV_Pen_Shadow]);      _Move(x1,y2);     _Draw(x1,y1);     _Draw(x2,y1);
  329.       _APen(pn[FV_Pen_HalfShadow]);  _Move(x1+1,y2);   _Draw(x1+1,y1+1); _Draw(x2,y1+1);
  330.       _APen(pn[FV_Pen_Fill]);        _Boxf(x1+2,y1+2,x2,y2);
  331.    }
  332. }
  333. //+
  334.  
  335.